import request from "@/utils/request";
import type {
  GetAttrListApiParams,
  AttrList,
  AttrItem,
} from "./model/attrModel";
// 枚举类型
// 当前模块的所有请求地址定义在一起（统一定义接口地址）
const enum Api {
  getAttrList = "/admin/product/attrInfoList",
  addOrUpdateAttr = "/admin/product/saveAttrInfo",
  delAttr = "/admin/product/deleteAttr",
}

/**
 * 获取属性列表
 * @param GetAttrListApiParams
 * @returns AttrList
 */
export const getAttrListApi = ({
  category1Id,
  category2Id,
  category3Id,
}: GetAttrListApiParams) => {
  return request.get<any, AttrList>(
    Api.getAttrList + `/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 * 添加或更新属性
 * @param data AttrItem
 * @returns null
 */
export const addOrUpdateAttrApi = (data: AttrItem) => {
  return request.post<any, null>(Api.addOrUpdateAttr, data);
};

/**
 * 删除属性
 * @param id 属性id
 * @returns null
 */
export const delAttrApi = (id: number) => {
  return request.delete<any, null>(Api.delAttr + `/${id}`);
};
